﻿using System;
using NDBGen.Descriptors.Columns.Tokens;

namespace NDBGen.Plugins.Descriptors.Columns.Tokens
{
    [ColumnTokenScriptSnippetGenerator(typeof(IdentityDeclarationTokenDescriptor))]
    public sealed class SqlServerIdentityDeclarationScriptGenerator : SqlServerColumnTokenScriptGeneratorBase<IdentityDeclarationTokenDescriptor>, IOrderedMetadata
    {
        private const String SQL_FORMAT = "identity({0},{1})";
        
        protected override void WriteSql(IIndentedTextWriter writer)
        {
            writer.Write(SQL_FORMAT, this.Descriptor.Seed ?? 1, this.Descriptor.Increment ?? 1);            
        }
        
        Int32 IOrderedMetadata.GenerationIndex { get { return 2; } }
    }
}